<?php

class Search {

    protected $dbo = NULL;

    public function __construct() {

        $this->dbo  = &DBO::getInstance();
    }

    public function searchArtists($string, $offset = 0, $limit = 50) {

        $res = $this->dbo->getAll("SELECT *
            FROM mtl.artists_view
            WHERE name ILIKE ?
            ORDER BY name ASC
            OFFSET ?
            LIMIT ?",
            array(
                DBString::create('%'.$string.'%'),
                DBInteger::create($offset),
                DBInteger::create($limit)
            ),
            DB_FETCHMODE_ASSOC);

        throwOnError($res);

        return $res;
    }

    public function searchReleases($string, $offset = 0, $limit = 50) {

        $res = $this->dbo->getAll("SELECT *
            FROM mtl.releases_view
            WHERE name ILIKE ?
            ORDER BY name ASC
            OFFSET ?
            LIMIT ?",
            array(
                DBString::create('%'.$string.'%'),
                DBInteger::create($offset),
                DBInteger::create($limit)
            ),
            DB_FETCHMODE_ASSOC);

        throwOnError($res);

        return $res;
    }


}